package apache.openejb.session.bean.stateless.client;

import java.net.InetAddress;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

import apache.openejb.session.bean.stateless.HelloWorldLocal;

public class HelloWorldLocalClient{
    
    public static void main(String[] args) throws Exception{
        Properties props = new Properties();
        props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
        //same vm in same machine
        props.put(Context.PROVIDER_URL, "http://localhost:8080/tomee/ejb");

        Context ctx = new InitialContext(props);
        Object ref = ctx.lookup("HelloWorldImplLocal");
        HelloWorldLocal r = (HelloWorldLocal)PortableRemoteObject.narrow(ref, HelloWorldLocal.class);

        String hostname = InetAddress.getLocalHost().getHostName();

        String result = r.sayHello("Hello World by local client <in different vm> at " + hostname);
        System.out.println(result); 
    }
}